

import requests
import re
import os
import shutil

if os.path.exists('static/豆瓣电影'):
	shutil.rmtree('static/豆瓣电影')
os.mkdir('static/豆瓣电影')



header = {
	'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36',
	'referer': 'https://movie.douban.com/',
}

top250_url = 'https://movie.douban.com/top250?start=0&filter='



response = requests.get(top250_url,headers=header)

data = response.text

info = re.findall(r'<div class="pic">.*?href="(.*?)">.*?alt="(.*?)" src="(.*?)">.*?</div>',data,re.S)

for i in info:
	title = i[1]
	datil_url = i[0]
	img_url = i[2]
	img_response = requests.get(img_url,headers=header)
	with open(f'static/豆瓣电影/{title}.jpeg','wb') as f:
		f.write(img_response.content)
	datil_response = requests.get(datil_url,headers=header)
	datil_data = datil_response.text
	print(datil_data)
	# datil_info = re.findall(r'<span class="all hidden">(.*?)<br />(.*?)</span>',datil_data,re.S)
	# if len(datil_info) == 0:
	# 	datil_info = re.findall(r'<span property="v:summary">(.*?)<br />(.*?)</span>',datil_data,re.S)
	# 	print(datil_info)
	# 	# total_datil = datil_info[0][0].strip() + datil_info[0][1].strip()
	# else:
	# 	# total_datil = datil_info[0][0].strip() + datil_info[0][1].strip()
	# 	print(datil_info)
	# print(total_datil)
	

	


